package cn.xiaoyu.su.controller;


import cn.xiaoyu.su.service.ProductService;
import cn.xiaoyu.su.util.JsonData;
import cn.xiaoyu.su.vo.ProductVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ⼆当家⼩D
 * @since 2022-12-18
 */
@RestController
@RequestMapping("/api/product/v1")
public class ProductController {

    @Autowired
    private ProductService productService;

    /**
     * 查看商品列表
     * @return
     */
    @GetMapping("list")
    public JsonData list() {

        List<ProductVO> productVOList = productService.list();

        return JsonData.buildSuccess(productVOList);

    }

    /**
     * 查看商品详情
     * @param productId
     * @return
     */
    @GetMapping("detail/{product_id}")
    public JsonData detail(@PathVariable("product_id")Long productId) {

        ProductVO productVO = productService.findDetailById(productId);

        return JsonData.buildSuccess(productVO);
    }
}

